<%--
 *  File:    Lang.jsp
 *  @Author: Langer wang
 *  Date:    2002-11-18
 *
 *  Copyright (C) 2000 - 2002 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>
<%@ page import="java.util.*" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%@ page import="com.oval.foundation.util.*" %>
<%@ page import="com.oval.foundation.engine.*" %>
<%
  String strModuleName = "COM";
%>

<%@ include file="/inc/PageDefault.inc" %>

<html>
<head>
<title><%= label.getLabelName("L_Lang") %></title>
<PageFlow:CheckPageFlow pageName="lang"/>
<%
  OvalLabel co = new OvalLabel(strLanguageCode,request.getParameter("module"));
  int colindex = 0;
  String formName = request.getParameter("form");
  if(request.getParameter("colindex") != null)
    colindex = Integer.parseInt(request.getParameter("colindex"));
  int fromIndex = colindex*ConstantProp.multiLangNumber;
  Vector contents = (Vector)pageContext.getAttribute("contents");
  HashMap MLCInfo = new HashMap();
  String entityType = request.getParameter("entitytype");
  String entityId = request.getParameter("entityid");
  String contentId = request.getParameter("contentid");
  if(contents == null)
    contents = new Vector();
  boolean isEdit = (contents.size()!=0);
  for(int i=0;i<contents.size();i++)
  {
    HashMap temp = (HashMap)contents.get(i);
    MLCInfo.put(temp.get("languagecode"),temp.get(request.getParameter("entitytype")));
    MLCInfo.put(temp.get("languagecode") + "_" + "ID",temp.get(contentId));
  }
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../js/ScriptLib.js"></script>
<script language="JavaScript">
var primaryContent = "";
function page_setMultiLang()
{
  if(!checkForm(frm)) return;
  if(<%=JspHelper.filterNull( isEdit )%>) emptyToNull(frm);
  if(isEmpty(primaryContent)) primaryContent = " ";
	if(opener == null) return;
	for(i=0;frm.elements[i]!=null;i++)
	{
		var elem = frm.elements[i];	
		var pe = eval("self.opener.document.<%=JspHelper.filterNull( formName )%>." + elem.name);
		if(pe != null)
		{
		  if(isEmpty(elem.value))
		    elem.value = primaryContent;
		  pe.value = elem.value;
		}else{
        addElementToOtherForm(self.opener.document,self.opener.document.<%=JspHelper.filterNull( formName )%>,elem.name,elem.value,false,"hidden");
		}
		var cd = eval("self.opener.document.<%=JspHelper.filterNull( formName )%>.<%=JspHelper.filterNull( contentId )%>" + elem.idx);
		if(cd != null)
		{
		  cd.value = elem.<%=JspHelper.filterNull( contentId )%>;
		}else{
        addElementToOtherForm(self.opener.document,self.opener.document.<%=JspHelper.filterNull( formName )%>,"<%=JspHelper.filterNull( contentId )%>" + elem.idx,elem.<%=JspHelper.filterNull( contentId )%>,false,"hidden");
		}		
  }
  <%--[SCRIPT]  alert(frmToString(frm));  [SCRIPT]--%>
  window.close();
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="frm">
<table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
  <tr> 
    <td colspan="2"><%= label.getLabelName("L_CategoryName") + label.getLabelName("L_Colon") %><%=JspHelper.filterNull( co.getLabelName(request.getParameter("mlctype")) )%></td>
  </tr>
  <tr class="deepblue-left"> 
    <td class="td_center" width="65"><%= label.getLabelName("L_Lang") %></td>
    <td class="td_center"><%= label.getLabelName("L_Content") %></td>
  </tr>
  
  <%
  String ct = "td-text";
  int primaryCnt = 0;
  String cmd = "";
  String name = entityType;
  String oc = "";
  for(int j=0;j<ConstantProp.multiLangInfo.size();j++){
    HashMap temp=(HashMap)ConstantProp.multiLangInfo.get(j);
    if(temp.get("languagecode").equals(session.getAttribute("languagecode")))
    {
      if("need".equals(request.getParameter("nativelanguage"))){
        ct = "need";
        cmd = "notnull";
      }
      oc = "onchange=\"javascript:changePrimary()\"";
      primaryCnt = j;
    }else{
      oc = "";
      ct = "td-text";
      cmd = "";
    }
  %>
  <tr> 
    <td class="<%=JspHelper.filterNull( ct )%>"><%= label.getLabelName("L_"+((String)temp.get("languagecode")).toUpperCase()) %></td>
    <td class="none"> 
      <input type="text" <%=JspHelper.filterNull( oc )%> label="<%=label.getLabelName("L_"+((String)temp.get("languagecode")).toUpperCase(),false)  %>" name="<%=JspHelper.filterNull( name + (fromIndex + j) )%>" idx="<%=JspHelper.filterNull( (fromIndex + j) )%>" command="<%=JspHelper.filterNull( cmd )%>" size="30" value="<%=JspHelper.filterNull( MLCInfo.get(temp.get("languagecode")) )%>" <%=JspHelper.filterNull( contentId )%>="<%=JspHelper.filterNull( MLCInfo.get(temp.get("languagecode") + "_" + "ID") )%>">
    </td>
  </tr>
  <%}%>  
</table>
</form>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="td_center">
     <a onclick="page_setMultiLang()"><custom:button type="1" label="L_Save" imgsrc="save.gif" border="0" style="width:60" privilegeCode="MB-PP04"/></a>
     <a onclick="window.close()"><custom:button type="1" label="L_Close" imgsrc="close.gif" border="0" style="width:60"/></a>
    </td>
  </tr>
</table>
</body>
<script language="javascript">
<%
for(int j=0;j<ConstantProp.multiLangInfo.size();j++){
  HashMap temp=(HashMap)ConstantProp.multiLangInfo.get(j);
%>
var o<%=JspHelper.filterNull( j )%> = eval("self.opener.document.<%=JspHelper.filterNull( formName )%>.<%=JspHelper.filterNull( entityType + (j + fromIndex) )%>");
var t<%=JspHelper.filterNull( j )%> = eval("frm.<%=JspHelper.filterNull( entityType + (j + fromIndex) )%>");
if(o<%=JspHelper.filterNull( j )%> != null && t<%=JspHelper.filterNull( j )%> != null && (!isEmpty(o<%=JspHelper.filterNull( j )%>.value) || <%= strLanguageCode.equals((String)temp.get("languagecode")) %>))
{
  t<%=JspHelper.filterNull( j )%>.value = o<%=JspHelper.filterNull( j )%>.value;
}
<%}%>
changePrimary();
function changePrimary()
{
  if(frm.<%=JspHelper.filterNull( entityType + primaryCnt )%> != null)
    primaryContent = frm.<%=JspHelper.filterNull( entityType + (primaryCnt + fromIndex) )%>.value;
}
</script>
</html>


